package com.david.tvhelperapp

import android.app.IntentService
import android.content.Intent
import android.util.Log
import com.david.tvhelperapp.msgdealers.*

class TvMsgService : IntentService("msgReceiveService") {
    override fun onCreate() {
        super.onCreate()
        initMsgDealers()
    }

    override fun onHandleIntent(intent: Intent?) {
        if (!TvMsgReceiver.getTvInstance().isRunning) {
            TvMsgReceiver.getTvInstance().startReceive()
        }
    }


    private fun initMsgDealers() {
        TvMsgReceiver.getTvInstance().channelMsgDealer = ChannelMsgDealer()
        val lightMsgDealer = LightMsgDealer()
        TvMsgReceiver.getTvInstance().channelMsgDealer.nextDealer = lightMsgDealer

        val voiceMsgDealer = VoiceMsgDealer()
        lightMsgDealer.nextDealer = voiceMsgDealer

        val appMsgDealer = AppMsgDealer()
        voiceMsgDealer.nextDealer = appMsgDealer

        val movieMsgDealer = MovieMsgDealer()
        appMsgDealer.nextDealer = movieMsgDealer

        val defaultMsgDealer = DefaultMsgDealer()
        movieMsgDealer.nextDealer = defaultMsgDealer
    }
}